package com.hamll.search.web;

import com.hamll.search.pojo.ItemDoc;
import com.hamll.search.pojo.RequestParams;
import com.hamll.search.service.SearchService;
import com.hmall.common.dto.PageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/search")
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

//    http://localhost:10010/search/list
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params){
        return searchService.findByPage(params);
    }

    @GetMapping("/suggestion")
    public List<String> suggestion(@RequestParam("key")String key){
        return searchService.getSuggest(key);
    }

    @PostMapping("/filters")
    public Map<String,List<String>> filters(@RequestBody RequestParams params){
        return searchService.filters(params);
    }
}
